package com.cll.learn.monitor.thread;

import java.util.Date;

/**
 * 描述信息:
 *
 * @author CLL
 * @version 1.0
 * @date 2020/9/29 10:30
 */
public class BaseTask  extends Thread{

    /**
     * 创建时间
     */

    private final Date gmtCreate;

    /**
     * 开始执行时间
     */
    private Date startTime;

    /**
     * 执行完成时间
     */
    private Date endTime;

    public BaseTask(ThreadGroup group, Runnable target, String name) {
        super(group, target, name);
        this.gmtCreate = new Date();
    }

    @Override
    public void run() {
        setStartTime();
        super.run();
        setEndTime();
    }

    public Date getGmtCreate() {
        return gmtCreate;
    }

    public Date getStartTime() {
        return startTime;
    }

    public synchronized void setStartTime() {
        this.startTime = new Date();
    }

    public Date getEndTime() {
        return endTime;
    }

    /**
     * 设置任务开始时间
     */
    public synchronized void setEndTime() {
        this.endTime = new Date();
    }

    @Override
    public String toString() {
        return getName() + ": gmtCreate=" + gmtCreate + " ; startTime=" + getStartTime() + " ; endTime=" + getEndTime();
    }
}
